//
//  MacroDefinition.h
//  SportsLand
//
//  Created by Mi on 14-10-4.
//  Copyright (c) 2014年 Mi. All rights reserved.
//

//----------------------系统设备相关----------------------------
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [UIApplication sharedApplication].delegate.window
#define AppDelegateInstance	 ((AppDelegate*)([UIApplication sharedApplication].delegate))
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

//获取设备屏幕尺寸
#define SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

//获取设备屏幕尺寸
#define APP_WIDTH  [[UIScreen mainScreen]applicationFrame].size.width
#define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height

//水平、垂直布局格子大小均为10（5S上）,用于适配
#define GRIDW (([UIScreen mainScreen].bounds.size.width)/32)
#define GRIDH (([UIScreen mainScreen].bounds.size.height)/56)

//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)
#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)
#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9)

#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7)
#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8)

#define isIOS7OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=7)
#define isIOS8OrAfter ([[[UIDevice currentDevice] systemVersion] intValue]>=8)
//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//判断是否 Retina屏、设备是否iphone 5、是否是iPad
#define isIphone6OrAfter [[UIScreen mainScreen] bounds].size.width > 320.0f
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
//----------------------property属性快速声明----------------------------
#define lPropertyString(s)                @property(nonatomic,copy)NSString * s
#define lPropertyNSInteger(s)             @property(nonatomic,assign)NSIntegers
#define lPropertyBool(s)                  @property(nonatomic,assign)BOOL s
#define lPropertyFloat(s)                 @property(nonatomic,assign)floats s
#define lPropertyDouble(s)                @property(nonatomic,assign)double s
#define lPropertyNSDictionary(s)          @property(nonatomic,strong)NSDictionary * s
#define lPropertyNSMutableDictionary(s)   @property(nonatomic,strong)NSMutableDictionary *s
#define lPropertyNSArray(s)               @property(nonatomic,strong)NSArray * s
#define lPropertyCopyNSArray(s)           @property(nonatomic,copy)NSArray * s
#define lPropertyNSMutableArray(s)        @property(nonatomic,strong)NSMutableArray *s
#define lPropertyCopyNSMutableArray(s)    @property(nonatomic,copy)NSMutableArray * s
//----------------------图片相关----------------------------
//读取本地图片
#define LoadImage(file,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]
#define LoadPNGImage(file) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:@"png"]]
//定义UIImage对象
#define ImageNamed(name)   [UIImage imageNamed:name]
//可拉伸的图片
#define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]
#define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]
//图片尺寸
#define CustomSizeImage(url,width,height) [NSString stringWithFormat:@"%@?imageView2/1/w/%d/h/%d",url,width,height]
//----------------------字体相关---------------------------
/** 字体*/
#define FONT(x) [UIFont systemFontOfSize:x]
#define LGFBoldFont(x) [UIFont boldSystemFontOfSize:x]
//----------------------颜色相关---------------------------
//颜色转换
#define XFUIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0F]

#define XFUIColorFromRGBA(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]
// 获取RGB颜色
#define RGB(r,g,b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0]
#define RGBA(r,g,b,a)  [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
//颜色
#define lColorClear       [UIColor clearColor]
#define lColorWhite       [UIColor whiteColor]
#define lColorBlack       [UIColor blackColor]
#define lColorGray        [UIColor grayColor]
#define lColorGray2       [UIColor lightGrayColor]
#define lColorBlue        [UIColor blueColor]
#define lColorRed         [UIColor redColor]
#define lColorRandomColorKRGB (arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)//随机色生成
//----------------------判断相关----------------------------
//字符串是否为空
#define StringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define ArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
//字典是否为空
#define DictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)

//----------------------视图相关----------------------------
//得到视图的left top的X,Y坐标点
#define VIEW_TX(view) (view.frame.origin.x)
#define VIEW_TY(view) (view.frame.origin.y)
//得到视图的right bottom的X,Y坐标点
#define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width)
#define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height)
//得到视图的尺寸:宽度、高度
#define VIEW_W(view)  (view.frame.size.width)
#define VIEW_H(view)  (view.frame.size.height)
//得到frame的X,Y坐标点
#define FRAME_X(frame)  (frame.origin.x)
#define FRAME_Y(frame)  (frame.origin.y)
//得到frame的宽度、高度
#define FRAME_W(frame)  (frame.size.width)
#define FRAME_H(frame)  (frame.size.height)

//---------------------打印日志--------------------------
#ifdef DEBUG
#define LGFLog(FORMAT, ...) fprintf(stderr,"[%s in line %d] ==> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define LGFLog(...)
#endif

//   模式下打印日志,当前行并弹出一个警告
#ifdef DEBUG
#   define LGFALERT(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define LGFALERT(...)
#endif

//打印Frame
#define LogFrame(frame)   NSLog(@"Frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)
//打印Size
#define LogSize(size)     NSLog(@"Size[W=%.1f,H=%.1f",size.width,size.height)
//打印Point
#define LogPoint(point)   NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y)
//打印Log
#define Log(fmt, ...)     NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
//---------------------- file ----------------------------
//读取文件的文本内容,默认编码为UTF-8
#define FileString(name,ext)            [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil]
#define FileDictionary(name,ext)        [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]
#define FileArray(name,ext)             [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]
//G－C－D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//获取沙盒Document路径
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒temp路径
#define kTempPath NSTemporaryDirectory()
//获取沙盒Cache路径
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//----------------------SOMETHING ELSE 其他 ----------------------------
#define lIntToString(S)          [NSString stringWithFormat:@"%zd",S]
#define lFloatToString(S)        [NSString stringWithFormat:@"%lf",S]
#define lObjectiveToString(S)    [NSString stringWithFormat:@"%@",S]

//拼接字符串
#define AppendString(string,addstring)  [string stringByAppendingString:addstring]
//----------------------程序相关----------------------------

//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)

// block self
#define WEAKSELF typeof(self) __weak weakSelf = self;
/** 字体*/
#define FONT(x) [UIFont systemFontOfSize:x]
#define SVPTIME 0.75
#define STOREAPPID @"1187797434"
#define LNETWORKERROR @"网络不稳定,请稍后重试."

#define LCOLOROFNAV   XFUIColorFromRGB(0x06C2AD)
#define LCOLOROFBACK   XFUIColorFromRGB(0xf1f1f1)

//通知
#define lNOTIF_ADD(n, f) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(f) name:n object:nil]
#define lNOTIF_POST(n, o) [[NSNotificationCenter defaultCenter] postNotificationName:n object:o]
#define lNOTIF_REMV() [[NSNotificationCenter defaultCenter] removeObserver:self]


